package light.head.framework.utils;

import java.io.IOException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class Base64Utils {
	/**
	 * base64加密
	 * @param 要加密的byte数组
	 * @return 密文
	 * @author 简航 创建日期 2009-08-03 00:46:56
	 */
	public static String base64Encrypt(byte[] byteList) {
		BASE64Encoder en = new BASE64Encoder();
		String encodeStr = en.encode(byteList);

		encodeStr = encodeStr.replace("\r\n", "");
		encodeStr = encodeStr.replace("\r", "");
		encodeStr = encodeStr.replace("\n", ""); 

		return encodeStr;
	}

	/**
	 * base64解密
	 * @param 密文
	 * @return 解密后的byte数组
	 * @author 简航 创建日期 2009-08-03 00:49:55
	 */
	public static byte[] base64Decrypt(String cryStr) {
		try {
			BASE64Decoder dec = new BASE64Decoder();
			return dec.decodeBuffer(cryStr);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}
